package app.view.mediators
{
	import app.AppConstants;
	import app.view.component.QuickEdit;
	
	import flash.events.MouseEvent;
	
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;

	public class QuickEditMediator extends Mediator
	{
		public static const NAME:String = "QuickEditMediator"
		public function QuickEditMediator(viewComponent:Object=null)
		{
			super(NAME, viewComponent);
		}
		
		override public function onRegister():void{
			view.addEventListener(MouseEvent.CLICK, onClick);			
		}
		
		private function onClick( event:MouseEvent ):void{
			if(event.currentTarget === event.target)return;
			switch(event.target.name){
				case "createStateBtn":
					sendCreateState();
					//view.nameCreateTI.text = "";
					break;
					
				case "deleteStateBtn":
					sendDeleteState();
					//view.nameDeleteTI.text = "";
					break;
					
				case "createActionBtn":
					sendCreateAction();
					/* view.fromStateTI.text = "";
					view.toStateTI.text = "";
					view.actionNameCreateTI.text = ""; */
					break;
					
				case "deleteActionBtn":
					sendDeleteAction();
					/* view.fromStateDeleteTI.text = "";
					view.actionNameDeleteTI.text = ""; */
					break;
			}
		}
		
		private function sendCreateAction():void{
			sendNotification( 	AppConstants.CREATE_NEW_ACTION, 
								view.fromStateTI.text + ":" + view.toStateTI.text, 
								view.actionNameCreateTI.text )
		}
		
		private function sendDeleteAction():void{
			sendNotification( AppConstants.REMOVE_ACTION, view.fromStateDeleteTI.text, view.actionNameDeleteTI.text )
		}
		
		private function sendCreateState():void{
			sendNotification( AppConstants.CREATE_NEW_STATE, view.pkgTI.text, view.nameCreateTI.text )
		}
		private function sendDeleteState():void{
			sendNotification( AppConstants.REMOVE_STATE, null, view.nameDeleteTI.text )
		}
		
		
		private function get view():QuickEdit{
			return QuickEdit(viewComponent);
		}
		
	}
}